﻿using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Product_1_2.Views
{
	/// <summary>
	/// Interaction logic for Product_1_2_View.xaml
	/// </summary>
	public partial class Product_1_2_View : UserControl, IInputView
	{
		ServiceReference1.Container context = new ServiceReference1.Container(new Uri("http://localhost:1179/odata"));

        private InputPresenter _presenter;
        private readonly IUnityContainer container;
        private readonly IRegionManager rManager;

        public event EventHandler Result;

        public string Number
        {
            get
            {
                return this.LotNumber.Text.ToString();
            }
        }

        public string Year
        {
            get
            {
                return this.YearCbx.Text.ToString();
            }
        }

        public string Month
        {
            get
            {
                return this.MonthCbx.Text.ToString();
            }
        }

        public string Day
        {
            get
            {
                return this.DayCbx.Text.ToString();
            }
        }

        public string Quantity
        {
            get
            {
                return this.Product_Quantity.Text.ToString();
            }
        }
        public Product_1_2_View()
        {
            InitializeComponent();
        }
        public Product_1_2_View(InputPresenter presenter, IUnityContainer c, IRegionManager r) : this()
        {
        

            _presenter = presenter;
            _presenter.View = this;

            container = c;
            rManager = r;

            this.Hot6ListView.ItemsSource = (IEnumerable)context.Hot6;

            this.materialsListView.ItemsSource = from kkk in context.Materials
                                                 where kkk.Pro_Id == 4
                                                 select kkk;

            this.materialsListView1.ItemsSource =
                                                from kkk in context.Materials
                                                where kkk.Pro_Id != 4
                                                select kkk;

            this.LotNumber.ItemsSource = from kkk in context.LotNumbers
                                         where kkk.Pro_Id == 4
                                         select new
                                         {
                                             PM_LotNumber = kkk.Lot_LotNumber
                                         };
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.HotListView2.ItemsSource = from kkk in context.Hot6
                                               select new
                                               {

                                                   Hot_Name = kkk.Hot_Name,
                                                   Hot_Quantity = kkk.Hot_Quantity * (Convert.ToInt32(this.Product_Quantity.Text))
                                               };
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

            Uri viewNav = new Uri("Product_2_2_View", UriKind.Relative);
            rManager.RequestNavigate(RegionNames.MainContentRegion, viewNav);

            Result(this, null);
        }
	}
}
